@extends('admin.layouts.master')
@section('css')
    <link rel="stylesheet" href="{{asset('/css/admin/commodity_edit.css')}}">
    <style>
        .shop_manage{
            background: #393F64;
        }
        .goods_manage{
            background: none;
        }
    </style>
@endsection
@section('content')
    {{--表头--}}
    <div class="main_header clearfix">
        <div class="main_header_show clearfix">
            <span>店铺详情</span>
        </div>

        <div class="main_header_edit clearfix" style="width: auto;">
            {{--<div class="add_box" data-toggle="modal" data-target="#myModal" style="width: 155px;">--}}
                {{--<img src="{{asset('images/update_icon.png')}}" alt="">--}}
                {{--<span>修改店铺密匙</span>--}}
            {{--</div>--}}
            <div class="add_box" data-toggle="modal" data-target="#myModal">
                <img src="{{asset('images/update_icon.png')}}" alt="">
                <span>编辑</span>
            </div>
            <div class="add_box change_state" data-toggle="modal" style="width: 120px;" status="{{$shopinfo->status}}}">
                <img src="{{asset('images/update_icon.png')}}" alt="">
                <span class="shop_status top_shop_status">
                    @if($shopinfo->status==0)
                        开启店铺
                    @elseif($shopinfo->status==1)
                        关闭店铺
                    @endif</td>
                </span>
            </div>
        </div>
    </div>
    {{--主要的内容区上半部分--}}
    <div class="main_form clearfix" style="height: auto;">
        <!-- 编辑区 -->
        <div class="main_infolist">
            <div class="main_editarea clearfix">
                <img src="{{asset('images/kele.jpg')}}" alt="">
                <div class="peson_infolist clearfix" style="height: auto;">
                    <div class="peson_left clearfix" style="overflow: hidden;">

                        <li>
                            <span>店铺名称&nbsp;:</span>
                            <span>{{$shopinfo->shop_name}}</span>
                        </li>
                        <li>
                            <span>地    址&nbsp;:</span>
                            <span>{{$shopinfo->shop_info}}</span>
                        </li>
                        <li style="position: relative;height:40px;">
                            <span>店铺密匙&nbsp;:</span>
                            <span style="white-space:nowrap;width:170px;text-overflow:ellipsis;overflow:hidden;position: absolute;top:20px;left: 0px;">{{$shopinfo->shop_secret}}</span>
                        </li>
                    </div>
                    <div class="peson_right" style="overflow: hidden;">
                        <li>
                            <span>店铺编号&nbsp;:</span>
                            <span>{{$shopinfo->id}}</span>
                        </li>
                        <li>
                            <span>开业时间&nbsp;:</span>
                            <span>{{$shopinfo->shop_date}}</span>
                        </li>
                        <li>
                            <span>开业状态&nbsp;:</span>
                            <span class="shop_status">
                                @if($shopinfo->status==0)
                                    未营业
                                @elseif($shopinfo->status==1)
                                    营业中
                                    @endif</td>
                            </span>
                        </li>
                    </div>
                </div>
            </div>
            <div id="allmap" style="margin:0 auto;min-height: 120px;"></div>
            <div style="font-size: 24px;max-height:300px;margin: 0 auto;width: 92%;margin-bottom: 20px;">
                <p style="color: #B5B5B5">店铺动态</p>
                <div style="border: 1px solid #B5B5B5;min-height: 50px;">
                    <?php
                        if(!empty($orderinfo)){
                            foreach($orderinfo as $key => $val){
                                if($key == 1)
                                    $html = '<div style="margin-top: 10px;"><div style="margin-left: 2%;float: left;">'.$val['pay_time'].'</div><div style="margin-left: 3%;float:left;max-width:70%;">'.$val['name'].'</div></div><div style="clear:both"></div>';
                                else
                                    $html = '<div style="color: #ccc;"><span style="margin-left: 2%;float: left;">'.$val['pay_time'].'</span><span style="margin-left: 3%;float:left;max-width:70%;">'.$val['name'].'</span></div><div style="clear:both"></div>';
                                echo $html;
                            }
                        }
                    ?>
                </div>
            </div>

        </div>
    </div>
@endsection
<!-- Modal -->
<div style="display: none;margin-top: 100px;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 350px;margin-left: 180px;">
            <div class="modal-header" style="background: #3D446B;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: white;"><span aria-hidden="true"><img
                                src="{{asset('/images/cancel_icon.png')}}" alt=""></span></button>
                <h4 class="modal-title" id="myModalLabel" style="color: white;text-align: center; font-size: 24px;">新增</h4>
            </div>
            <div class="modal-body">
                <div class="modal_info clearfix">
                    <p class="blinfo"><span>店铺名称</span><br>
                        <input type="text" name="shop_name" class="shop_name" value="{{$shopinfo->shop_name}}" readonly="readonly">
                    </p>
                    <p class="blinfo"><span>店铺编号</span><br>
                        <input type="text" name="shop_id" class="shop_id" value="{{$shopinfo->id}}">
                    </p>
                    <p class="blinfo"><span>店铺地址</span><br>
                        <input type="text" name="shop_info" class="shop_info" value="{{$shopinfo->shop_info}}">
                    </p>
                    <p class="blinfo"><span>店铺密钥</span><br>
                        <span>
                            <input type="text" name="shop_secret" class="shop_secret" value="{{$shopinfo->shop_secret}}">
                            <input type="submit" value="修改" class="btn btn-primary change_key" style="height:30px;border: 0px solid;width: 50px;background: #2BAAF7;float: right;margin-top: -32px;margin-right: -60px;">
                        </span>
                    </p>
                    <p class="blinfo"><span>开业日期</span><br>
                        <input type="text" name="shop_date" class="shop_date" value="{{$shopinfo->shop_date}}">
                    </p>
                    <label for="flast_class">店铺状态</label>
                    <select name="fid" class="form-control shop_state">
                        @if($shopinfo->state == 1)
                            <option value="1" selected>店铺开业</option>
                            <option value="0">店铺未开业</option>
                        @else
                            <option value="1">店铺开业</option>
                            <option value="0" selected>店铺未开业</option>
                        @endif
                    </select>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <input type="submit submit_key" value="提交" class="btn btn-primary submit_key" style="height:40px;border: 0px solid;width: 300px;background: #2BAAF7;margin-top:90px;"/>
            </div>
        </div>
    </div>
</div>
@section('js')
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3W1MFos8Akm82Ku0EDYLrhlXfWYOplWh"></script>
<script>
    $(function(){
        var point = "{{$shopinfo->point}}";
        $('#allmap').css({'height':'200px','width':'92%'});
        var map = new BMap.Map("allmap",{minZoom:12,maxZoom:18});  // 创建Map实例
        map.centerAndZoom('上海', 11);
        map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
        map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
        point = point.split(",");
        var marker = new BMap.Marker(new BMap.Point(point[0], point[1]));  // 创建标注
        map.addOverlay(marker);               // 将标注添加到地图中
    })
    $(".submit_key").click(function (){
        var shop_id     = $('.shop_id').val();
        var shop_secret = $('.shop_secret').val();
        var shop_name   = $('.shop_name').val();
        var shop_info   = $('.shop_info').val();
        var shop_date   = $('.shop_date').val();
        var shop_state  = $('.shop_state').val();
        $.ajax({
            type : 'post',
            dataType:'json',
            data : {"shop_id":shop_id,"shop_secret":shop_secret,"shop_name":shop_name,"shop_info":shop_info,"shop_date":shop_date,"state":shop_state,'_token': "{{csrf_token()}}"},
            url  : '/admin/shop/save_data',
            success:function(msg){
                if(msg.code == 200){
                    alert('修改成功');
                    var url = '/admin/shop/show/'+shop_id;
                    window.location.href = url;
                    return false;
                }else{
                    alert(msg.msg);
                    return false;
                }
            }
        });
    })
    $(".change_key").click(function (){
        $.ajax({
            type      : 'post',
            dataType : 'json',
            data      : {'id' :"{{$shopinfo->id}}"},
            url       : '/admin/shop/change_key',
            success   : function(msg){
                if(msg.code != 200){
                    alert('生成店铺密匙出错');
                    return false;
                }else{
                    $(".shop_secret").val(msg.data);
                }
            }
        })
    });
    $(".change_state").click(function (){
        var state   = $(".change_state").attr('status');
        var shop_id = "{{$shopinfo->id}}";
        var string = '';
        var string1 = '';
        if(state == 1){
            state = 0;
            string = '关闭店铺';
            string1 = '开启店铺';
        }else{
            state = 1;
            string = '开启店铺';
            string1 = '关闭店铺';
        }
        $.ajax({
            type : 'post',
            data : {'state':state,'shop_id':shop_id},
            dataType : 'json',
            url  : '/admin/shop/change_key',
            success: function(msg){
                if(msg.code == 200){
                    $(".shop_status").html(string);
                    $(".top_shop_status").html(string1);
                    $(".change_state").attr('status',state);
                }else{
                    alert('修改店铺状态失败');
                    return false;
                }
            }
        });
    })
</script>
@endsection
